package com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.item;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hq.fxh.No3_TuiGuang.MyMoBan.Activity.AdBannerInfo;
import com.hq.fxh.R;
import com.hq.fxh.Utils.GlideUtils;


/**
 * @author 大圣
 * @ClassName CardAdComtentItem
 * @Description : 名片广告内容
 * @Created 2015/12/22 0022
 * @Email qwqe601660957@163.com
 */
public class CardAdComtentItem extends LinearLayout {
    /**
     * 名片广告图片
     */
    private ImageView ivCardPic;
    /**
     * 名称
     */
    private TextView tvName;
    /**
     * 手机号
     */
    private TextView tvPhone;
    /**
     * 地址
     */
    private TextView tvAddress;
    private RelativeLayout llCardAd;
    private ViewGroup.LayoutParams params;

    //    private AppCompatCheckBox cbPic;
    public CardAdComtentItem(Context context) {
        super(context);
        inflate(context, R.layout.item_card_ad_content, this);
        initView();
    }

    private void initView() {
        ivCardPic = (ImageView) findViewById(R.id.ivCardPic);
        tvName = (TextView) findViewById(R.id.tvName);
        tvPhone = (TextView) findViewById(R.id.tvPhone);
        tvAddress = (TextView) findViewById(R.id.tvAddress);
        llCardAd = (RelativeLayout) findViewById(R.id.llCardAd);
//        cbPic = (AppCompatCheckBox) findViewById(R.id.cbPic);
//        params = llCardAd.getLayoutParams();
//        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
//        int width = wm.getDefaultDisplay().getWidth();
//        params.height = width*250/750;
    }

    /**
     * @param adInfo
     */
    public void showAdInfo(final AdBannerInfo adInfo) {
        if (adInfo != null) {
            final AdBannerInfo.AdvertDetailBean merchantArticleCardModel = adInfo.getAdvert_detail();
            if (merchantArticleCardModel != null) {
                tvName.setText(merchantArticleCardModel.getName());
                tvPhone.setText(merchantArticleCardModel.getMobile());
                tvAddress.setText(merchantArticleCardModel.getAddress());
//                final Pic cardPic = merchantArticleCardModel.getCardPic();
//                if(cardPic != null){
//                    if(cardPic.isNative()){
//                        Bitmap bitmap = ImageUtils.bytes2Bimap(Base64.decode(cardPic.getPicData(), Base64.DEFAULT));
//                        ivCardPic.setImageBitmap(bitmap);
//                    }else{
                GlideUtils.loadImage(getContext(), merchantArticleCardModel.getPic(), ivCardPic);
                //        GlideUtils.loadRoundedImage(getContext(),merchantArticleCardModel.getPic(),getContext().getResources().getDimensionPixelSize(R.dimen.size_6),ivCardPic);
//                    }

            }
        }
    }
}
